home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-06-25 | 8.4 KB | 193 lines | [TEXT/MACA] |
- ; (c) Copyright 1990 by University of Massachusetts. All rights reserved.
- ; This software was conceived, designed, and written by Dan Suthers
- ; while supported by the National Science Foundation under grant number
- ; MDR 8751362, and by a fellowship from Apple Computer, Inc., Cupertino,
- ; CA. Partial support was also received from the Office of Naval Research
- ; under a University Research Initiative Grant, contract N00014-86-K-0764.
- ; Mr. Suthers created this software under his own initiative while in an
- ; academic relationship with the University of Massachusetts. The above
- ; copyright notice was a condition placed by University lawyers on approval
- ; of distribution of this software by Apple Computer, and is not meant to
- ; imply that this software was created in an employment or "work for hire"
- ; relationship between the University and Mr. Suthers.
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; File: UTILITY.LISP
- ; Author: Dan Suthers
- ; Created: 15-Oct-86 01:37:00
- ; Modified: 22-Jun-90 01:59:22 (Dan Suthers)
- ; Language: LISP
- ; Package: UTILS
- ;
- ; Description: CORAL ALLEGRO (MACINTOSH) VERSION.
- ; General utilities (mostly documentation access), and machine
- ; dependent utilities. Application specific but machine
- ; independent utilities have been split into other files.
- ;
- ; Status: Should be working.
- ;
- ; (c) Copyright 1987, by Daniel D. Suthers
- ; Department of Computer and Information Science
- ; University of Massachusetts
- ; Amherst, Massachusetts 01003
- ;
- ; This software was conceived, designed, and written by Dan Suthers
- ; while supported by the National Science Foundation under grant number
- ; MDR 8751362, and by a fellowship from Apple Computer, Inc., Cupertino,
- ; CA. Partial support was also received from the Office of Naval Research
- ; under a University Research Initiative Grant, contract N00014-86-K-0764.
- ; I wish to acknowledge the generous support of Beverly Woolf, who obtained
- ; the above grants and encouraged me to pursue my own research interests in
- ; her lab. This work would not have been possible without the resources and
- ; stimulating environment of the Computer and Information Science department.
- ;
- ; Permission to use, modify, and distribute this software is granted subject
- ; to the following restrictions and understandings:
- ; 1. The file header, including this notice, shall be retained, and may be
- ; extended to include documentation of modifications to the software.
- ; 2. This material is for nonprofit educational and research purposes only.
- ; Users are requested, but not required, to inform Mr. Suthers of any
- ; noteworthy uses of this software.
- ; 3. Mr. Suthers and the University of Massachusetts make no warrantee or
- ; representation that the operation of this software will be error free,
- ; and are under no obligation to provide any services.
- ; 4. Any user of such software agrees to indemnify and hold harmless Mr.
- ; Suthers and the University of Massachusetts from all claims arising
- ; out of the use or misuse of this software, or arising out of any
- ; accident, injury, or damage whatsoever, and from all costs, counsel
- ; fees, and liabilities incurred in or about any such claim, action, or
- ; proceeding brought thereon.
- ; 5. All materials and reports developed as a consequence of the use of
- ; this software shall duly acknowledge such use, in accordance with
- ; the usual standards of acknowledging credit in academic research.
- ;
- ;
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (in-package :UTILS :use '(lisp))
-
- (export '(
- DATE-AND-TIME-STRING
- #+VAX DCL
- DOC
- DOC*
- PDOC
- #+:CCL USE-PACKAGE!
- WHEREIS
- ))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- (defun DATE-AND-TIME-STRING ()
- "date-and-time-string [Function]
- Returns a string of the current date/time in the format 01-Jan-99 12:34:45"
- (multiple-value-bind
- (second minute hour date month year)
- (get-decoded-time)
- (format nil "~2,'0D-~A-~2,'0D ~2,'0D:~2,'0D:~2,'0D"
- date
- (case month
- ((1) "Jan")
- ((2) "Feb")
- ((3) "Mar")
- ((4) "Apr")
- ((5) "May")
- ((6) "Jun")
- ((7) "Jul")
- ((8) "Aug")
- ((9) "Sep")
- ((10) "Oct")
- ((11) "Nov")
- ((12) "Dec"))
- (- year 1900)
- hour minute second)))
-
- #+VAX
- (defun DCL (command-string)
- "dcl <command-string> [Function]
- Spawns a VMS DCL process to execute the command."
- (spawn :command-string command-string))
-
- (defun DOC* (sym &key (stream *standard-output*))
- "doc* sym &key (stream *standard-output*) [Function]
- Prints function and/or variable documentation of the indicated symbol to
- <stream>. Returns nil, unless <stream> is nil, in which case a string is
- returned instead of printing."
- (let* ((fundoc (if (fboundp sym) (documentation sym 'function)))
- (vardoc (if (boundp sym) (documentation sym 'variable)))
- (doc-string
- (with-output-to-string (s)
- (cond ((and fundoc vardoc)
- (format s "~S~% Function:~% ~A~% Variable:~% ~A"
- sym fundoc vardoc))
- (fundoc
- (format s "~S~% Function:~% ~A" sym fundoc))
- (vardoc
- (format s "~S~% Variable:~% ~A" sym vardoc))
- (T
- (format s "~S Exported but undocumented ~A."
- sym
- (if (fboundp sym)
- "Function" "Variable")))))))
- (if stream (format stream "~A" doc-string) doc-string)))
-
-
- (defmacro DOC (sym &key (stream *standard-output*))
- "doc sym &key (stream *standard-output*) [Macro]
- Prints function and/or variable documentation of the indicated symbol to
- <stream>. Returns nil, unless <stream> is nil, in which case a string is
- returned instead of printing. Only the second argument is evaluated (see
- DOC* for functional version)."
- "doc <fsymbol> [Macro]
- Prints documentation of a function."
- `(doc* ',sym :stream ',stream))
-
- (defmacro PDOC (package-name &key (stream *standard-output*))
- "pdoc <package-name> &key (stream *standard-output*) [Macro]
- Prints all documentation of all exported symbols in a package.
- See DOC for details; the only difference is this won't return
- a string collecting all the results if <stream> is nil."
- `(let* ((*package* (or (find-package (string ',package-name))
- (warn "There is no package called ~S" package-name)))
- (symbols nil))
-
- (when *package*
- (format T
- "~%
- ------------------------------------------------------------------------------
- Documentation for Exported Symbols in Package ~A:"
- ',package-name)
- (do-external-symbols (sym *package*)
- (push sym symbols))
- (dolist (sym (sort symbols
- #'(lambda (s1 s2)
- (string< (symbol-name s1) (symbol-name s2)))))
- (format ',stream "~%~%")
- (doc* sym :stream ',stream)))))
-
-
- #+:CCL
- (defun USE-PACKAGE! (package)
- "use-package! <package> [Macro]
- Just like use-package, but forces use by uninterning possible conflicts
- first. This is needed in Allegro because a symbol conflict is not a
- continuable error."
- (do-external-symbols (sym package)
- (if (find-symbol (symbol-name sym) *package*)
- (unintern (find-symbol (symbol-name sym) *package*) *package*)))
- (use-package package))
-
- (defmacro WHEREIS (SYM)
- "whereis <symbol> [Macro]
- Finds and prints all packages a symbol is in."
- `(dolist (p (list-all-packages))
- (if (find-symbol ',(symbol-name sym) p)
- (progn
- (format T "; ~A" p)
- (if (eq p *package*)
- (format T " (the current package)"))))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- (provide :utility)
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;;; EOF
-